package com.nf.action;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import org.apache.struts2.interceptor.SessionAware;

import java.util.Map;

/*
定义拦截器有2种办法：
1.实现Interceptor接口
2.集成AbstractInterceptor抽象类
 */
public class LoginInterceptor implements Interceptor {

    private Map<String,Object> session = null;


    public void destroy() {

    }

    public void init() {

    }

    public String intercept(ActionInvocation actionInvocation) throws Exception {
        //网上大部分代码
        session = ActionContext.getContext().getSession();
        Object user = session.get("user");
        if (user!=null){
            return actionInvocation.invoke();
        }else{
            return "login";
        }
        //return actionInvocation.invoke();
    }

}
